package com.xs.aifitnessagent.resp;

import com.xs.aifitnessagent.enums.ReturnCodeEnum;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 返回数据封装类
 *
 * @author lambor
 */
@Data
@Accessors(chain = true)
public class ResultData<T> {

    /**
     * 状态码
     * 具体状态码参见枚举类 ReturnCodeEnum
     */
    private String code;

    /**状态信息**/
    private String message;

    /**数据**/
    private T data;

    /**时间戳**/
    private long timestamp;

    /**调用链追踪ID**/
    private String traceId;

    public ResultData () {
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> ResultData<T> success(T data) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(ReturnCodeEnum.RC200.getCode());
        resultData.setMessage(ReturnCodeEnum.RC200.getMessage());
        resultData.setData(data);
        return resultData;
    }

    public static <T> ResultData<T> fail(String code, String message) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(code);
        resultData.setMessage(message);
        return resultData;
    }
}
